package com.zenith.article.controller;

import com.zenith.article.po.domain.ArtArticle;
import com.zenith.article.po.dto.ArtArticleDTO;
import com.zenith.article.service.ArtArticleService;
import com.zenith.common.annotation.request.SecurePostMapping;
import com.zenith.common.result.Result;
import com.zenith.common.result.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 文章主表控制器
 *
 * @author zenith
 * @since 2025-08-29
 */
@RestController
@RequestMapping("/api/article")
@Tag(name = "文章管理", description = "文章相关接口")
public class ArtArticleController {

    @Autowired
    private ArtArticleService artArticleService;

    /**
     * 分页查询文章
     */
    @Operation(summary = "分页查询文章")
    @SecurePostMapping("/getArtArticlePage")
    public Result<PageResult<ArtArticle>> getArtArticlePage(ArtArticleDTO query) {
        PageResult<ArtArticle> pageResult = artArticleService.getArtArticlePage(query);
        return Result.success(pageResult);
    }

    /**
     * 创建文章
     */
    @Operation(summary = "创建文章")
    @SecurePostMapping("createArtArticle")
    public Result<Boolean> createArtArticle(@RequestBody ArtArticleDTO articleDTO) {
        boolean result = artArticleService.createArtArticle(articleDTO);
        return Result.success(result);
    }

    /**
     * 更新文章
     */
    @Operation(summary = "更新文章")
    @SecurePostMapping("updateArtArticle")
    public Result<Boolean> updateArtArticle(@RequestBody ArtArticleDTO articleDTO) {
        boolean result = artArticleService.updateArtArticle(articleDTO);
        return Result.success(result);
    }

    /**
     * 删除文章
     */
    @Operation(summary = "删除文章")
    @SecurePostMapping("/deleteArtArticle/{id}")
    public Result<Boolean> deleteArtArticle(@PathVariable Long id) {
        boolean result = artArticleService.deleteArtArticle(id);
        return Result.success(result);
    }

    /**
     * 发布文章
     */
    @Operation(summary = "发布文章")
    @SecurePostMapping("/publishArtArticle/{id}/publish")
    public Result<Boolean> publishArtArticle(@PathVariable Long id) {
        boolean result = artArticleService.publishArtArticle(id);
        return Result.success(result);
    }

    /**
     * 获取文章详情
     */
    @Operation(summary = "获取文章详情")
    @SecurePostMapping("/getArtArticleDetail/{id}")
    public Result<ArtArticleDTO> getArtArticleDetail(@PathVariable Long id) {
        ArtArticleDTO articleDTO = artArticleService.getArtArticleDetail(id);
        return Result.success(articleDTO);
    }
}